package com.ysdz.tibetan.tibetanmini.wechat.utils;

import com.ysdz.tibetan.tibetanmini.wechat.exception.AesException;

public class WXPublicUtils {

    private static final String TOKEN = "yuzhivmblo";

    /**
     * 验证Token
     * @param msgSignature 签名串，对应URL参数的 signature
     * @param timeStamp 时间戳，对应URL参数的 timestamp
     * @param nonce 随机串，对应URL参数的 nonce
     *
     * @return 是否为安全签名
     * @throws AesException 执行失败，请查看该异常的错误码和具体的错误信息
     */
    public static boolean verifyUrl(String msgSignature, String timeStamp, String nonce)
            throws AesException {
        String signature = SHA1.getSHA1(TOKEN, timeStamp, nonce);
        if (!signature.equals(msgSignature)) {
            throw new AesException(AesException.ValidateSignatureError);
        }
        return true;
    }
}
